package com.reremouse.rerebbs.web.mb;

import com.reremouse.rerebbs.dao.IBbsFileDAO;
import com.reremouse.rerebbs.model.BbsFileModel;
import com.reremouse.rerebbs.model.BbsUser;
import com.reremouse.service.ComplexFileLogic;
import com.reremouse.util.JsfHelper;
import com.reremouse.util.SpringHelper;

import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpServletRequest;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

@ManagedBean
@ViewScoped
public class ClientListFile
        implements Serializable {
    IBbsFileDAO project2DAO = (IBbsFileDAO) SpringHelper.getSpringBean("BbsFileDAO");
    ComplexFileLogic complex = (ComplexFileLogic) SpringHelper.getSpringBean("ComplexFileLogic");
    List<BbsFileModel> pro2s;
    long uid = 1L;
    long fatherID = 0L;
    long grapaID = 0L;
    String folderName = "00";
    String temp = "";
    List<BbsFileModel> familyTree = new ArrayList();

    public List<BbsFileModel> getFamilyTree() {
        return this.familyTree;
    }

    public void setFamilyTree(List<BbsFileModel> familyTree) {
        this.familyTree = familyTree;
    }

    public List<BbsFileModel> getPro2s() {
        return this.pro2s;
    }

    public void setPro2s(List<BbsFileModel> pro2s) {
        this.pro2s = pro2s;
    }

    public long getFatherID() {
        return this.fatherID;
    }

    public void setFatherID(long fatherID) {
        this.fatherID = fatherID;
    }

    public String getFolderName() {
        return this.folderName;
    }

    public void setFolderName(String folderName) {
        this.folderName = folderName;
    }

    public long getGrapaID() {
        return this.grapaID;
    }

    public void setGrapaID(long grapaID) {
        this.grapaID = grapaID;
    }

    @PostConstruct
    public void init() {
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String fid = request.getParameter("fid");
        if (fid != null) {
            this.fatherID = Long.parseLong(fid);
        }
        synDB();
        genGrapaID();
        this.familyTree = this.complex.genFamilyTree(this.fatherID);
    }

    public void synDB() {
        ClientSession cs = (ClientSession) JsfHelper.getBean(FacesContext.getCurrentInstance(), "clientSession");
        BbsUser bu = cs.getUsr();
        if (bu != null) {
            this.pro2s = this.project2DAO.findAllClientFileByUsr(bu.getId().longValue(), this.fatherID);
        }
    }

    private void genGrapaID() {
        if (this.fatherID != 0L) {
            long g = this.project2DAO.findClientFile(this.fatherID).getFatherID();
            this.grapaID = g;
        }
    }

    public String reBuild() {
        HttpServletRequest request = (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
        String fid = request.getParameter("fid");
        if (fid != null) {
            long id = Long.parseLong(fid);
            this.fatherID = id;
            System.out.println("FatherID:" + fid);
        } else {
            this.fatherID = 0L;
        }
        synDB();
        genGrapaID();
        this.familyTree = this.complex.genFamilyTree(this.fatherID);
        return null;
    }

    public String delPro(Long id) {
        if (id != null) {
            this.project2DAO.delClientFileAndAllDescendants(id.longValue());
        }
        synDB();
        return null;
    }

    public String batDel() {
        for (BbsFileModel cf : this.pro2s) {
            if (cf.isSelected()) {
                this.project2DAO.delClientFileAndAllDescendants(cf.getId());
            }
        }
        synDB();
        return null;
    }

    public String batChangeDir() {
        List<BbsFileModel> files = new ArrayList();
        for (BbsFileModel cf : this.pro2s) {
            if (cf.isSelected()) {
                files.add(cf);
            }
        }
        ChangeFileDir cfd = (ChangeFileDir) JsfHelper.getBean("changeFileDir");
        cfd.change(files);
        return null;
    }
}



/* Location:           F:\jsp源码\蝙蝠论坛系统\rerebbs\WEB-INF\classes\

 * Qualified Name:     com.reremouse.rerebbs.web.mb.ClientListFile

 * JD-Core Version:    0.7.0.1

 */